package com.muyu.system.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.system.domain.DanmoVipRights;
import com.muyu.system.service.IDanmoVipRightsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * vip权益Controller
 * 
 * @author yl
 * @date 2025-06-10
 */
@RestController
@RequestMapping("/rights")
public class DanmoVipRightsController extends BaseController
{
    @Autowired
    private IDanmoVipRightsService danmoVipRightsService;

    /**
     * 查询vip权益列表
     */
//    @RequiresPermissions("system:rights:list")
    @PostMapping("/list")
    public Result<List<DanmoVipRights>> list(@RequestBody DanmoVipRights danmoVipRights)
    {

        List<DanmoVipRights> list = danmoVipRightsService.selectDanmoVipRightsList(danmoVipRights);
        return Result.success(list);
    }

    /**
     * 导出vip权益列表
     */
//    @RequiresPermissions("system:rights:export")
    @Log(title = "vip权益", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoVipRights danmoVipRights)
    {
        List<DanmoVipRights> list = danmoVipRightsService.selectDanmoVipRightsList(danmoVipRights);
        ExcelUtil<DanmoVipRights> util = new ExcelUtil<DanmoVipRights>(DanmoVipRights.class);
        util.exportExcel(response, list, "vip权益数据");
    }

    /**
     * 获取vip权益详细信息
     */
//    @RequiresPermissions("system:rights:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoVipRightsService.selectDanmoVipRightsById(id));
    }

    /**
     * 新增vip权益
     */
//    @RequiresPermissions("system:rights:add")
    @Log(title = "vip权益", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoVipRights danmoVipRights)
    {
        return toAjax(danmoVipRightsService.insertDanmoVipRights(danmoVipRights));
    }

    /**
     * 修改vip权益
     */
//    @RequiresPermissions("system:rights:edit")
    @Log(title = "vip权益", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoVipRights danmoVipRights)
    {
        return toAjax(danmoVipRightsService.updateDanmoVipRights(danmoVipRights));
    }

    /**
     * 删除vip权益
     */
//    @RequiresPermissions("system:rights:remove")
    @Log(title = "vip权益", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoVipRightsService.deleteDanmoVipRightsByIds(ids));
    }


    /**
     * 自己是否是会员以及权益
     */
    @GetMapping("/getPersonRights")
    public List<DanmoVipRights> getPersonRights(@RequestParam("userid")  Long userid)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long userid1 = loginUser.getUserid();
       return danmoVipRightsService.getPersonRights(userid1);
    }
}
